XScale1 = MAGH1+1;         //XScale1 is the requested scale factor
PW1 = (DW1+1) / XScale1;   //PW1 is the requested X resolution in pixels
XScale2 = Max_Width/PW1;   //XScale2 is needed physical X scale factor
if(!XScale2){
 DW2 = Max_Width-1;
 DX2 = (Max_Width-PW1)/2 + Min_DX;
 MAGH2 = 0;
}else{
 if(XScale2 > 16)          //if XScale2 is larger than GS can handle
  XScale2 = 16;            //Limit XScale2 to valid range
 DW2 = (PW1 * XScale2)-1;  //DW2 is needed physical display width in VCK units-1
 MAGH2 = XScale2-1;        //MAGH2 is needed MAGH for result DISPLAYx
 DX2 = (Max_Width-1-DW2)/2 + Min_DX; //DX2 is the final horizontal parameter
}
if(DX2<0) DX2=0;           //Negative value is not allowed
if(DX2 < Min_DX){          //If used offset < physical offset
 DW2 += (Min_DX-DX2)       //increase DW2 by the same difference
}

YScale1 = MAGV1+1;         //YScale1 is the requested scale factor
PH1 = (DH1+1) / YScale1;   //PH1 is the requested Y resolution in pixels
YScale2 = Max_Height/PH1;  //YScale2 is needed physical Y scale factor
if(!YScale2){
 MAGV2 = 0;
 DH2 = Max_Height-1;
 DY2 = (Max_Height-PH1)/2 + Min_DY;
}else{
 if(YScale2 > 4)           //if YScale2 is larger than GS can handle
  YScale2 = 4;             //Limit YScale2 to valid range
 MAGV2 = YScale2-1;        //MAGV2 is needed MAGV for result DISPLAYx
 DH2 = (PH1 * YScale2)-1;  //DH2 is needed raster display height
 DY2 = (Max_Height-DH2-1)/2 + Min_DY; //DY2 is the final vertical parameter
}
if(DY2<0) DY2=0;           //Negative value is not allowed
if(DY2 < Min_DY){          //If used offset < physical offset
 DH2 += (Min_DY-DY2)       //increase DH2 by the same difference
}
